<form action="" id="form">
    <input type="text" name="text">
    <button>保存</button>
</form>
<ul id="root"></ul>
<script>
const key="logs"
const logs=JSON.parse(localStorage.getItem(key))||[]
const form=document.getElementById("form");
const render=()=>{
  
const root=document.getElementById("root")
root.innerHTML=logs.map(log=>`<li>${log.text}(${log.time})</li>`).join("")

}

form.addEventListener("submit",e=>{
    e.preventDefault()
    const text=form.text.value.trim()
    if(text.length==0) return
    const log={text,time:Date.now()}
    logs.push(log)
    localStorage.setItem(key,JSON.stringify(logs))
    form.text.value=''
    form.text.focus()
    render()
})
render()

</script>